package com.sys.controller;

import com.sys.common.aop.Operation;
import com.sys.common.constant.Constant;
import com.sys.common.util.ResponseDateUtil;
import com.sys.common.util.ResultBuilder;
import com.sys.pojo.EmployeeSalary;
import com.sys.service.EmployeeSalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 工资 前端控制器
 * </p>
 *
 * @author ZJF
 * @since 2021-04-01
 */
@Api(tags = {"工资管理"})
@RestController
@RequestMapping("/employeeSalary")
public class EmployeeSalaryController {

    @Resource
    private EmployeeSalaryService employeeSalaryService;

    @PostMapping("/salary")
    @RequiresPermissions("salary:add")
    @ApiOperation("添加工资信息")
    @Operation("添加工资信息")
    public ResponseDateUtil addSalary(@RequestBody EmployeeSalary vo) {
        String s = employeeSalaryService.addSalary(vo);
        if (s == Constant.ADDSUCCESS) {
            return ResultBuilder.success(Constant.ADDSUCCESS);
        } else {
            return ResultBuilder.errorInfo(s);
        }
    }

    @PostMapping("/salarys")
    @RequiresPermissions("salary:list")
    @ApiOperation("查看工资信息")
    public ResponseDateUtil pageInfo(@RequestBody EmployeeSalary vo) {
        return ResultBuilder.success(employeeSalaryService.pageEmployeeSalary(vo));
    }

    @PutMapping("/salaryUpd")
    @RequiresPermissions("salary:upd")
    @ApiOperation("更新工资信息")
    @Operation("更新工资信息")
    public ResponseDateUtil salaryUpd(@RequestBody EmployeeSalary vo) {
        Boolean aBoolean = employeeSalaryService.updSalary(vo);
        if (aBoolean) {
            return ResultBuilder.success();
        } else {
            return ResultBuilder.errorInfo(Constant.ADDSUCCESS);
        }
    }

}
